/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package systemsim;

import java.awt.*;
import java.util.HashMap;
import javax.swing.*;
import javax.swing.border.Border;


/**
 *
 * @author emil
 */
public class GUIQueue {
    
    JFrame guiQueue;
    Container contentPane;
    
    private HashMap<Group, JPanel> groupsInLine = new HashMap<Group, JPanel>();
    
    public GUIQueue()
    {
        guiQueue = new JFrame("Restaurant Queue     Size = 0");
        guiQueue.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        guiQueue.setSize(1280, 80);
        guiQueue.setBounds(0, 0, 1280, 80);
        guiQueue.setResizable(false);
        guiQueue.setAlwaysOnTop(true);
 
        //Set up the content pane.
        contentPane = guiQueue.getContentPane();
        BoxLayout layout = new BoxLayout(contentPane, BoxLayout.LINE_AXIS);
        contentPane.setLayout(layout);
        contentPane.setSize(1280, 80);
        
        guiQueue.setVisible(true);
        
    }
    
    public synchronized void add(Group group)
    {
        //System.out.println("REPAINT");
        Color color = Color.GREEN;
        if(group.getID()%2 == 0)
        {
            color = Color.ORANGE;
        }
        
        JPanel p = new JPanel();
        p.setSize(80, 80);
        p.setPreferredSize(new Dimension(80,80));
        p.setMaximumSize(new Dimension(80,80));
        BoxLayout l = new BoxLayout(p, BoxLayout.PAGE_AXIS);
        p.setLayout(l);
        //p.setAlignmentY(p.);
        
        Border loweredbevel = BorderFactory.createLoweredBevelBorder();
        Border raisedbevel = BorderFactory.createRaisedBevelBorder();
        p.setBorder(BorderFactory.createCompoundBorder(raisedbevel, loweredbevel));
        
    
        p.setBackground(color);
        JLabel guiGroup = new JLabel("Group: "+ group.getID());
        //item.setAlignmentX(0.5F);;
        guiGroup.setSize(80, 80);
        guiGroup.setBackground(color);
        //item.setBackground(Color.RED);
        guiGroup.setOpaque(true);
        p.add(guiGroup);
        
        guiGroup = new JLabel("numPpl: "+group.getNumPeople());
        guiGroup.setSize(80, 80);
        guiGroup.setBackground(color);
        guiGroup.setOpaque(true);
        p.add(guiGroup);
        
        p.setVisible(true);
        
        this.groupsInLine.put(group, p);
        contentPane.add(p);
        
        p.revalidate();
        guiQueue.validate();
        
        contentPane.repaint();
        guiQueue.repaint();
        
        //System.out.println("REPAINT");
    }
    
    public synchronized void remove(Group group)
    {
        JPanel toRemove;
        
        toRemove = this.groupsInLine.remove(group);
        
        contentPane.remove(toRemove);
        contentPane.validate();
        guiQueue.validate();
        
        contentPane.repaint();
        guiQueue.repaint();
        
        
        
        
    }
    
    public void setSizeDisplay(int size, boolean isRushHour)
    {
        if(isRushHour)
        {
            guiQueue.setTitle("Restaurant Queue     Size = "+size+"   It is RUSH HOUR!");      
        }
        else
        {
            guiQueue.setTitle("Restaurant Queue     Size = "+size+"");      
        }
        
    }
   
    public static void main(String[] args)
    {
       
        
        
//        JLabel item = new JLabel("Group");
//        item.setSize(80, 80);
//        item.setMaximumSize(new Dimension(80,80));
//        
//        contentPane.add(item);
//        
//        contentPane.add(Box.createRigidArea(new Dimension(5, 0)));
//        JPanel p = new JPanel();
//        p.setSize(80, 80);
//        p.setPreferredSize(new Dimension(80,80));
//        p.setMaximumSize(new Dimension(80,80));
//        p.setLayout(new BoxLayout(p, BoxLayout.PAGE_AXIS));
        



        
    }
}
